package com.lxl.mayi;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2022/3/30 17:03
 * @Description
 */
public class UserCarbon implements WritableComparable<UserCarbon> {

    private String userId;
    private String date;
    private Integer carbon;

    public UserCarbon() {
        super();
    }

    public UserCarbon(String userId, String date, Integer carbon) {
        this.userId = userId;
        this.date = date;
        this.carbon = carbon;
    }

    @Override
    public int compareTo(UserCarbon o) {
        String userId = o.getUserId();
        int userIdCompareRst = userId.compareTo(this.userId);
        if (userIdCompareRst ==0) {
            String date = o.getDate();
            return date.compareTo(this.date);
        }
        return userIdCompareRst;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(userId);
        out.writeUTF(date);
        out.writeInt(carbon);

    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.userId = in.readUTF();
        this.date = in.readUTF();
        this.carbon = in.readInt();
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public Integer getCarbon() {
        return carbon;
    }

    public void setCarbon(Integer carbon) {
        this.carbon = carbon;
    }

    @Override
    public String toString() {
        return userId + '\t' +date + '\t' + carbon;
    }
}
